package tags;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import beans.Perfil;
import dao.interfaces.PerfilDAO;
import factory.Factory;

public class PerfilTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	public int doStartTag() throws JspException{
		try {
		JspWriter out = pageContext.getOut();
		
		/*Se invoca a la facbrica MySql*/
		Factory factory = Factory.obtenerTipo(2);
		PerfilDAO pedao = factory.obtenerPerfilDAO();
		
		List<Perfil> lista = pedao.ListarPerfil();
		
		/*Se crea el control select*/
		out.write("<select  id = 'cboPerfil' name='cboPerfil'>") ;
		out.write("<option>--Seleccione--</option>");
				for (Perfil p : lista) {
					out.write("<option value='"+p.getCodigo()+"'>"+
							p.getDescripcion()+
							"</option>");
				}
		out.write("</select>");
		
	} catch (Exception e) {
		// TODO: handle exception
	}
		
		
		return SKIP_BODY;
	}
	

	@Override
	public int doEndTag() throws JspException{
		return EVAL_PAGE;
	}
}
